<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

/**
 *  配置 - app功能隐藏
 */
class SettingAppHidden extends Model
{
    protected $table = 'setting_app_hidden';

    const FUNC_PUSH = 1;
    const FUNC_WECHAT = 2;
    const FUNC_MSG = 3;
    const FUNC_NAV = 4;
    const FUNC_SHORT_VIDEO = 5;
    const FUNC_SEND_MSG_TIP = 6;
    const FUNC_GIFT = 7;
    const FUNC = [
        self::FUNC_PUSH => '推送提醒',
        self::FUNC_WECHAT => '微信入口',
        self::FUNC_MSG => '私信收费',
        self::FUNC_NAV => '底部导航隐藏',
        self::FUNC_SHORT_VIDEO => '短视频入口',
        self::FUNC_SEND_MSG_TIP => '开启发送消息消费提示',
        self::FUNC_GIFT => '屏蔽礼物入口'
    ];

    protected $fillable = ['func_type', 'app_id', 'channel', 'version', 'flag','week','end_time','begin_time', 'hidden_city'];

    // public function getAppidAttribute($keywords)
    // {
    //     return explode('-', $keywords);
    // }
    public function setAppidAttribute($appIds)
    {
        $this->attributes['app_id'] = implode(',', $appIds);
    }

    public function setChannelAttribute($channel)
    {
        $this->attributes['channel'] = implode(',', $channel);
    }

    public function setWeekAttribute($week) {
        $this->attributes['week'] = json_encode($week);
    }

    public function  getWeekAttribute($week)
    {
        $week = empty($week) ? [] : json_decode($week,true);
        return implode(',',$week);
    }

    public function setHiddenCityAttribute($hiddenCity)
    {
        $this->attributes['hidden_city'] = implode(',', $hiddenCity);
    }
}
